package com.mcptt.config.ue.initial.sub.sub;

import com.cloudptt.api.product.log.Log;
import com.mcptt.config.ue.initial.sub.DefaultUserProfile;
import com.mcptt.config.ue.initial.sub.McpttUeId;
import com.mcptt.config.ue.initial.sub.OnNetwork;
import com.mcptt.config.ue.initial.sub.sub.sub.ServiceDetails;

import org.jdom.Element;
import org.jdom.JDOMException;

import java.util.List;

public class AnyExt {
    public static final String Name = "anyExt";
    private static final String Name_Mcptt_Service_Details = "MCPTT-Service-Details";
    private static final String Name_Mcvideo_Service_Details = "MCVideo-Service-Details";
    private static final String Name_MCData_Service_Details = "MCData-Service-Details";
    private static final String Name_MCCommonCore_Service_Details = "MCCommonCore-Service-Details";

    private ServiceDetails mcpttPsi = null;
    private ServiceDetails mcvideoPsi = null;
    private ServiceDetails mcdataPsi = null;
    private ServiceDetails cmsPsi = null;

    public void parse(Element root) throws JDOMException
    {
        List<Element> list = root.getChildren();//锟斤拷酶锟斤拷诘锟斤拷锟接节碉拷
        for(Element elem:list)
        {
            String name = elem.getName();
            Log.debug(this.getClass(), "name = " + name);
            if(name == null
                    || name.length() <= 0)
            {
                return;
            }
            if(name.equals(Name_Mcptt_Service_Details))
            {
                mcpttPsi = new ServiceDetails();
                mcpttPsi.parse(elem);
            }
            else if(name.equals(Name_Mcvideo_Service_Details))
            {
                mcvideoPsi = new ServiceDetails();
                mcvideoPsi.parse(elem);
            }
            else if(name.equals(Name_MCData_Service_Details))
            {
                mcdataPsi = new ServiceDetails();
                mcdataPsi.parse(elem);
            }
            else if(name.equals(Name_MCCommonCore_Service_Details))
            {
                cmsPsi = new ServiceDetails();
                cmsPsi.parse(elem);
            }
        }
    }

    public ServiceDetails getMcpttPsi() {
        return mcpttPsi;
    }

    public ServiceDetails getMcvideoPsi() {
        return mcvideoPsi;
    }

    public ServiceDetails getMcdataPsi() {
        return mcdataPsi;
    }

    public ServiceDetails getCmsPsi() {
        return cmsPsi;
    }

    public String toString()
    {
        StringBuffer strBuf = new StringBuffer("\r\n");
        strBuf.append("<").append(Name).append(" ");
        strBuf.append(mcpttPsi);
        strBuf.append(mcvideoPsi);
        strBuf.append(mcdataPsi);
        strBuf.append(cmsPsi);
        strBuf.append("</").append(Name).append(" ");

        return strBuf.toString();
    }
}
